﻿using System;
using System.Runtime.Serialization;

namespace TripLOA.WebService.Wrappers
{
    /// <summary>
    /// A serializable rapresentation of the Groupware.Trip class
    /// </summary>
    [DataContract]
    public class TripInfo
    {
        #region Costructors

        /// <summary>
        /// Parameterless Constructor
        /// </summary>
        public TripInfo() { }

        /// <summary>
        /// Constructor. Set all fields to the values of the given Trip object
        /// </summary>
        /// <param name="t">Groupware.Trip object</param>
        public TripInfo(Groupware.Trip t)
        {
            this.ID = t.Id;
            this.Departure = t.Departure;
            this.Arrival = t.Arrival;

            //Tutti i campi sono nullable, in modo da poter anche avere il valore nullo
            this.DepartureDate = t.DepartureDate;
            this.EstimatedBudget = t.EstimatedBudget;

            if (!t.UserId.HasValue)
            {
                //ERRORE il viaggio non ha un ID
                return;
            }

            Security.TripLoaUser tlu = UserCore.Instance.GetLoggedUser();
            if (tlu == null)
            {
                //TODO throw an exception
            }
            Security.Profile profile = tlu.GetProfile(t.UserId.Value);
            this.Owner = new UserInfo() { UserID = t.UserId.Value, Username = profile.Username, NumericFeedbacks = UserCore.Instance.GetUserNumericFeedback(profile) };
        }

        #endregion

        #region Properties

        [DataMember]
        public int ID { get; set; }

        [DataMember]
        public UserInfo Owner { get; set; }

        [DataMember]
        public string Departure { get; set; }

        [DataMember]
        public string Arrival { get; set; }

        [DataMember]
        public DateTime? DepartureDate { get; set; }

        [DataMember]
        public decimal? EstimatedBudget { get; set; }

        #endregion
    }
}
